package qjc.z_排序;

import java.util.Arrays;

public class z1_冒泡排序 {
    /**
     * 对比相邻的两个元素，设置一个变量记录边界
     *
     * @param nums
     */
    private static void bubble(int[] nums) {
        int x = 0;
        int len = nums.length - 1;
        do {
            for (int i = 0; i < len; i++) {
                if (nums[i] > nums[i + 1]) {
                    int temp = nums[i];
                    nums[i] = nums[i + 1];
                    nums[i + 1] = temp;
                    x = i;
                }
            }
            len = x;
        } while (len != 0);
    }

    public static void main(String[] args) {
        int[] a = {6, 5, 4, 3, 2, 1};
        System.out.println(Arrays.toString(a));
        bubble(a);
        System.out.println(Arrays.toString(a));
    }
}
